﻿window.OrderGenerate = Backbone.Model.extend({

});

window.OrderGenerateView = Backbone.View.extend({
    el: '#jqt',
    initialize: function () {
        this.template = $('#GenerateOrderTemplate').html();
    },
    events: {
        'click .orderGenarate #BackToIndex': 'backToIndex',
        'click .orderGenarate #CheckOrder': 'goToMyOrder'
    },
    render: function () {
        var partial = { header: $('#HeaderTemplate').html(), footer: $('#FooterTemplate').html(),
            innerFooter: $('#InnerFooterTemplate').html()
        };
        var data = { btnListR: [{ name: 'home' }, { name: 'avatar'}] };
        this.$el.append(Mustache.render(this.template, data, partial));

        var carts = localStorage.getItem('orderno');
        if (carts) {
            var info = { OrderId: localStorage.getItem('orderno'), shouldpay: localStorage.getItem('shouldPay'), payment: localStorage.getItem('paymentstyle') };
            $('.orderGenarate').html(Mustache.render($('#GenerateOrderSuccessTemplate').html(), info, []));
            localStorage.removeItem('shouldPay'); 
            localStorage.removeItem('paymentstyle'); 
            localStorage.removeItem('orderno');
        } else {
            $('.orderGenarate').html(Mustache.render($('#GenerateOrderErrorTemplate').html(), [], []));
        }

        return this;
    },

    backToIndex: function () {
        pageView.goTo('Catalog');
    },

    goToMyOrder: function () {
        pageView.goTo('MyOrder');
    }
});